package sv.gob.mh.dgii.security;

import org.springframework.expression.Expression;
import org.springframework.security.access.ConfigAttribute;

/**
 * Simple expression configuration attribute for use in web request
 * authorizations. Based on the class of the same name in Spring Security which
 * is package-default.
 *
 * @author Luke Taylor
 * @author <a href='mailto:burt@burtbeckwith.com'>Burt Beckwith</a>
 */
public class WebExpressionConfigAttribute implements ConfigAttribute {

    private static final long serialVersionUID = 1L;
    private final Expression _authorizeExpression;

    /**
     * Constructor.
     *
     * @param authorizeExpression the expression
     */
    public WebExpressionConfigAttribute(final Expression authorizeExpression) {
        _authorizeExpression = authorizeExpression;
    }

    /**
     * Accessor for the expression.
     *
     * @return the expression
     */
    public Expression getAuthorizeExpression() {
        return _authorizeExpression;
    }

    /**
     * {@inheritDoc}
     *
     * @see org.springframework.security.access.ConfigAttribute#getAttribute()
     */
    @Override
    public String getAttribute() {
        return null;
    }

    @Override
    public String toString() {
        return _authorizeExpression.getExpressionString();
    }
}
